function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function(){
    $(".pic_info").submit(function (e) {
        e.preventDefault();
        // TODO 上传头像
        // ajaxSubmit: 是ajax请求和form表单的结合
        // ajax负责监听回调
        // form负责提交表单数据
        $(this).ajaxSubmit({
            url: "/user/pic_info",
            type: "POST",
            headers: {
                "X-CSRFToken": getCookie('csrf_token')
            },
            success: function (resp) {
                if (resp.errno == "0") {
                    $(".now_user_pic").attr("src", resp.data.pic_url);
                    $(".user_center_pic>img", parent.document).attr("src", resp.data.pic_url);
                    $(".user_login>a>img", parent.document).attr("src", resp.data.pic_url)
                    $('.input_sub').blur()
                }else {
                    alert(resp.errmsg)
                }
            }
        })
    })
});
